#![no_std]
#![no_main]
#![allow(dead_code)]
#![feature(allocator_api)]

extern crate alloc;

#[macro_use]
extern crate unistd;

#[global_allocator]
static GLOBAL_ALLOCATOR: linked_list_allocator::LockedHeap =
    linked_list_allocator::LockedHeap::empty();

const HEAP_SIZE: usize = 8 * 1024;

#[unsafe(no_mangle)]
extern "C" fn _start(rsdp_addr: usize, _fb_addr: usize) -> ! {
    let heap_start = unistd::mm::mmap(0, HEAP_SIZE, 0, 0x87);
    unsafe {
        GLOBAL_ALLOCATOR
            .lock()
            .init(heap_start as *mut u8, HEAP_SIZE);
    }

    acpi::init(rsdp_addr);
    pci::init();

    storage::blkdev::init();

    let mut buf = [0; 512];
    storage::blkdev::HD_LIST
        .lock()
        .get(0)
        .unwrap()
        .read_block(0, &mut buf);

    println!("{:#X?}", buf);

    loop {
        core::hint::spin_loop();
    }
}

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
    println!("{}", info);
    unistd::proc::exit(1)
}

mod acpi;
mod dma;
mod pci;
mod storage;
